//
//  TTOperation.h
//  Tint
//
//  Created by Kevin Wu on 2/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TTCore.h"
#import "TTAdditions.h"

#import "TTDelegatesProtocol.h"



typedef enum {
    TTOperationStateReady = 1, 
    TTOperationStateExecuting, 
    TTOperationStateFinished
} TTOperationState;



@protocol TTOperationDelegate;


@interface TTOperation : NSOperation<TTDelegatesProtocol> {
    NSError *_error;
    TTOperationState _state;
    
    BOOL _cancelled;
    
    NSMutableArray *_delegates;
}

@property(nonatomic, retain) NSError *error;
@property(nonatomic, assign) TTOperationState state;


- (void)operationDidStart;
- (void)operationUpdated;
- (void)operationDidFailWithError:(NSError *)error;
- (void)operationWillFinish;
- (void)operationDidFinish;

@end



@protocol TTOperationDelegate <NSObject>
@optional
- (void)operationDidStart:(TTOperation *)operation;
- (void)operationUpdated:(TTOperation *)operation;
- (void)operationDidFail:(TTOperation *)operation withError:(NSError *)error;
- (void)operationWillFinish:(TTOperation *)operation;
- (void)operationDidFinish:(TTOperation *)operation;
@end
